home *** CD-ROM | disk | FTP | other *** search
-
- /* File : moveto.c */
- /* Entered by : A. Wayner */
-
- # include <graphics.h>
- # include <stdlib.h>
-
-
- y[] = {1,3,5,4,6,8,5,6,8,9};
- x[] = {1,2,3,4,5,6,7,8,9,10};
- main()
- {
- int graphdriver = DETECT, graphmode, i,
- maxy = 10, maxx = 10,
- numpt, maxheight, maxwidth, xscale, yscale;
-
- numpt = sizeof( y ) / sizeof( int );
-
- /* Detect adapter type and */
- /* initialize graphics system */
- initgraph( &graphdriver, &graphmode, "\\turboc" );
- outtextxy( 10,10, "Use of 'moveto' in scatter graph");
-
- /* Now draw the x-y graph */
- maxheight = getmaxy() - 100;
- yscale = maxheight / maxy;
-
- maxwidth = getmaxx() - 200;
- xscale = maxwidth / maxx;
-
- setviewport( 100, 50, 100+maxwidth, 50 + maxheight, 1 );
- rectangle(0,0, maxwidth, maxheight);
-
- setcolor( WHITE );
- settextjustify( CENTER_TEXT, CENTER_TEXT );
-
- /* Scale the data and draw an 'x' */
- /* at each point */
- for( i = 0; i < numpt; i++ )
- {
- /* Our y-coordinates increase as */
- /* we go up */
- moveto(x[i] * xscale, maxheight - y[i] * yscale );
- outtext("X");
- }
-
- /* Wait until user presses a key */
- outtextxy( 10, getmaxy() - 30 ,"Press any key to exit");
- getch();
- closegraph();
-
- }
-